package cn.hnu.jpa.jpaExample.Composite_primary_key;

import java.io.Serializable;

public class CustomerPK implements Serializable{

	/**
	 * 复合主键首先需要编写一个复合主键的类 如 CustomPK 并且必须实现序列化接口
	 * 
	 * 必须要有无参的构造函数
	 * 
	 * 然后覆盖其hashcode 和  equals方法 EntityManager 通过find方法来查找Entity
	 * 
	 * 时，是根据equals的返回值来判断的。
	 * 
	 * 
	 */
	private static final long serialVersionUID = -3262738746277508907L;
	
	private String email;
	
	private String name;

	public CustomerPK() {
	}

	public CustomerPK(String email, String name) {
		this.email = email;
		this.name = name;
	}

	
	
	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((email == null) ? 0 : email.hashCode());
		result = PRIME * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if(this == obj)
			return true;
		if( obj == null)
			return false;
		if(getClass() != obj.getClass())
			return false;
		final CustomerPK other = (CustomerPK) obj;
		if(email == null){
			if(other.email != null)
				return false;
		}else if(!email.equals(other.email)){
			return false;
		}
		if(name == null){
			if(other.name != null)
				return false;
		}else if(!name.equals(other.name))
			return false;
		return true;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
}
